<script setup lang="ts">
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import { useUserInfoStore } from "@/stores/userInfo";
const userInfoStore = useUserInfoStore();
onLaunch(() => {
  console.log("App Launch");
  // const value = uni.getStorageSync("privacySatus");
  // if (value && value == 2) {
  //   uni.reLaunch({
  //     url: "/pages/crowd/home/index",
  //   });
  // } else {
  //   uni.reLaunch({
  //     url: "/pages/index/index",
  //   });
  // }
  // 如果已有授权信息直接进入对应首页，反之进去群众端首页
  if (userInfoStore.token && userInfoStore.openId) {
    toHomePage(userInfoStore.userInfo.userType);
  }
});
onShow(() => {
  console.log("App Show");
  // 如果已有授权信息直接进入对应首页，反之进去群众端首页
  if (userInfoStore.token && userInfoStore.openId) {
    toHomePage(userInfoStore.userInfo.userType);
  }
});
onHide(() => {
  console.log("App Hide");
});
onLoad(() => {});
// 进入对应首页
const toHomePage = (userType: any) => {
  console.log("userType------" + userType);
  // 1群众 2民警 3所领导
  if (userType == 1) {
    uni.redirectTo({
      url: "/pages/crowd/home/index",
    });
  }
  if (userType == 2) {
    uni.redirectTo({
      url: "/pages/police/home/index",
    });
  }
  if (userType == 3) {
    uni.redirectTo({
      url: "/pages/leader/home/index",
    });
  }
};
</script>
<style lang="scss">
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
@import "uview-plus/index.scss";
@import "@/static/css/common.css";

page {
  background-color: #f4f5f9;
}
</style>
